﻿using System;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media.Animation;
using System.Collections;
using System.Windows.Browser;
using System.Windows.Browser.Net;
using System.Net;
using System.IO;

namespace AgLux
{
    public enum Filling { full = 100, threeFourth = 75, half = 50, oneFourth = 25 }
    public enum State { shown, hidden, changing }
    
    /// <summary>
    /// //
    /// </summary>

    public partial class Start : Canvas
    {
        private EventHandler resizeHandler;
        private MouseEventHandler clickHandler;
        private string _a = "funkar inte :(";
        
        /// <summary>
        /// //
        /// </summary>

        /// <param name="sender">
        /// //
        /// </param>

        /// <param name="args">
        /// //
        /// </param>

        public void PageLoaded(object sender, EventArgs args)
        {
            resizeHandler = new EventHandler(WindowResized);
            BrowserHost.Resize += resizeHandler;
            AgLux.localhost.Service1 hej = new AgLux.localhost.Service1();
            _a = hej.HelloWorld("gris");
           
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="sender">
        /// //
        /// </param>

        /// <param name="args">
        /// //
        /// </param>

        private void WindowResized(object sender, EventArgs args)
        {
            InitializeComponent();
            test.Text = _a;

            Width = BrowserHost.ActualWidth;
            Height = BrowserHost.ActualHeight;

            agluxLogotype.SetValue(Canvas.LeftProperty, Width / 2 - agluxLogotype.Width / 2);
            agluxLogotype.SetValue(Canvas.TopProperty, Height / 2 - agluxLogotype.Height / 2);

            aglux.SetValue(Canvas.LeftProperty, Width / 2 - aglux.Width / 2);
            aglux.SetValue(Canvas.TopProperty, Height / 2 - aglux.Height / 2);

            developed.SetValue(Canvas.LeftProperty, Width / 2 - developed.ActualWidth / 2);
            developed.SetValue(Canvas.TopProperty, Height / 2 - developed.ActualHeight / 2);

            silverlightLogotype.SetValue(Canvas.LeftProperty, Width / 2 - silverlightLogotype.Width / 2);
            silverlightLogotype.SetValue(Canvas.TopProperty, Height / 2 - (silverlightLogotype.Height + microsoft.Height + silverlight.Height + 30) / 2);

            microsoft.SetValue(Canvas.LeftProperty, Width);
            microsoft.SetValue(Canvas.TopProperty, Height / 2 - (silverlightLogotype.Height + microsoft.Height + silverlight.Height + 30) / 2 + silverlightLogotype.Height + 10);

            silverlight.SetValue(Canvas.LeftProperty, -silverlight.Width);
            silverlight.SetValue(Canvas.TopProperty, Height / 2 - (silverlightLogotype.Height + microsoft.Height + silverlight.Height + 30) / 2 + silverlightLogotype.Height + microsoft.Height + 20);
            
            by.SetValue(Canvas.LeftProperty, Width / 2 - by.Width / 2);
            by.SetValue(Canvas.TopProperty, Height / 2 - by.Height / 2);

            microsoftDistance.Value = -(Width / 2 + silverlight.Width / 2);
            silverlightDistance.Value = Width / 2 + silverlight.Width / 2;

            intro.Begin();
            intro.Completed += new EventHandler(IntroEnded);

            clickHandler = new MouseEventHandler(PagePressed);
            MouseLeftButtonDown += clickHandler;
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="sender">
        /// //
        /// </param>

        /// <param name="args">
        /// //
        /// </param>

        private void PagePressed(object sender, MouseEventArgs args)
        {
            intro.Stop();
            agluxSignature.Stop();

            IntroEnded(sender, args);
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="sender">
        /// //
        /// </param>

        /// <param name="args">
        /// //
        /// </param>

        private void IntroEnded(object sender, EventArgs args)
        {
            BrowserHost.Resize -= resizeHandler;
            MouseLeftButtonDown -= clickHandler;

            Resources.Clear();
            Children.Clear();
            Children.Add(Parser.ParseCourseFromXml("silverlight"));
        }
    }
}
